q<template>
    <div class="edu-page-warp">
        <ConditionCard
            shadow="never"
            body-style="padding: 24px 24px 6px 24px;"
            @search="onSubmit"
            @reset="reset('queryForm')"
        >
            <el-form ref="queryForm" :model="queryForm" label-position="right" label-width="90px">
                <el-row :gutter="16">
                    <el-col :span="8">
                        <el-form-item label="辅修年级:" prop="grade">
                            <el-date-picker
                                style="width:100%"
                                v-model="queryForm.condition.grade"
                                type="year"
                                value-format="yyyy"
                                placeholder="请选择"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('minor.major.college') + ':'" prop="schoolId">
                            <el-select
                                clearable
                                v-model="queryForm.condition.schoolId"
                                placeholder="请选择学校"
                                @change="queryAdvancedLevelBySchool"
                                :filterable="true"
                                style="width:100%;"
                            >
                                <el-option
                                    v-for="item in options.schoolId"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="辅修专业:" prop="minorMajorId" class="no-bottom">
                            <el-select
                                clearable
                                v-model="queryForm.condition.minorMajorId"
                                :filterable="true"
                                placeholder="请选择"
                                style="width:100%;"
                            >
                                <el-option
                                    v-for="item in options.minorMajorId"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="16">
                    <el-col :span="8">
                        <el-form-item label="进阶层次:">
                            <el-select
                                clearable
                                v-model="queryForm.condition.advancedLevel"
                                style="width:100%;"
                                @change="queryMinorMajorCondition"
                                placeholder="请选择"
                            >
                                <el-option
                                    v-for="item in options.advancedLevel"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="是否在籍:" prop="name">
                            <el-input
                                v-model="queryForm.condition.name"
                                autocomplete="off"
                                placeholder="请输入姓名"
                                style="width:100%;"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="结业状态:" prop="recruitStatus">
                            <el-select
                                clearable
                                v-model="queryForm.condition.recruitStatus"
                                placeholder="请选择"
                                style="width:100%;"
                            >
                                <el-option
                                    v-for="item in options.recruitStatus"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </ConditionCard>
        <el-card shadow="never" body-style="padding: 24px;" class="card-margin">
            <h1 class="condition-title">辅修学籍列表</h1>
            <div class="div-main clearfix">   
                <div class="float-left">
                    <KeywordInput
                        v-model="queryForm.condition.keyWord"
                        @enter="handleSearch"
                        placeholder="学号/姓名"
                    ></KeywordInput>
                </div>
                <div class="float-right">
                    <el-button @click="exportFile()">导出</el-button>
                </div>
            </div>
            <EduTable
                @page-change="pageChange"
                :data="tableData.list"
                :total="tableData.total_"
                @selection-change="selectionChange"
            >
                <el-table-column prop="entranceTerm" label="辅修年级" show-overflow-tooltip></el-table-column>
                <el-table-column prop="studentNum" label="学号" show-overflow-tooltip></el-table-column>
                <el-table-column prop="name" label="姓名" show-overflow-tooltip></el-table-column>
                <el-table-column prop="faulty" label="学院" show-overflow-tooltip></el-table-column>
                <el-table-column prop="cultrueProfession" label="专业" show-overflow-tooltip></el-table-column>
                <el-table-column prop="cultrueProfession" :label="$t('minor.major.college')" show-overflow-tooltip></el-table-column>
                <el-table-column prop="majorNameZn" label="辅修专业" show-overflow-tooltip></el-table-column>
                <el-table-column prop="advancedLevelName" label="进阶层次"></el-table-column>
                <el-table-column prop="minorGradePoint" label="是否在籍" show-overflow-tooltip></el-table-column>
                <el-table-column prop="totalAvgGradePoint" label="结业状态" show-overflow-tooltip></el-table-column>
            </EduTable>
        </el-card>
    </div>
</template>
<script>
import UTILS from "common/src/utils/utils";
import { queryDic, findTrainingLevelByProjId, advanceExport } from "common/src/api/dictionary";
import { findFaculty } from "common/src/api/faculty";
import { findProfessionByParam,getPower } from 'common/src/api/culture/bachelor';
import {
    queryMinorCultureSchemeList,
    exportCultureSchemePdfOrWordZip,
} from "common/src/api/minor/minorCultureScheme";
import mixin from 'common/src/mixins/index';
export default {
    name: "CultureSchemeQuery",
    mixins: [mixin],
    data() {
        return {
            isGraduate: true,
            showAdvanceExport: false,
            queryForm: {
                condition: {
                    "x-token": "",
                    grade: "", // 年级
                    trainingLevel: "", // 培养层次
                    faculty: "", // 学院
                    projId: "", //	部门管理
                    professionCateGory: "", //专业类别(1 专业大类 2 专业),
                    campusProfession: "", //	本科生专业
                    major: "", // 研究生专业
                    type: "", // pdf或者word
                    status: "", // 状态 选项通过审批的培养方案
                    formLearning: "", // 学习形式
                    trainingCategory: [], //培养类别
                    name: "", // 名称
                    degreeType: "",  // 学位类型
                },
                pageNum_: 1,
                pageSize_: 20
            },
            options: {
                project: [],
                trainingLevel: [],
                professionCateGory: [],
                faculty: [],
                major: [],
                semester: [],
                formLearning: [],
                trainingCategory: [], // 培养类别,
                professionCateGory: [
                    { value: "", label: this.$t("message.all") },
                    {
                        value: "1",
                        label: this.$t("culture.profession.bigProfession")
                    },
                    {
                        value: "2",
                        label: this.$t("culture.profession.profession")
                    }
                ],
                campusProfessions: [],
                currentRole: '',
                degreeType: []
            },
            tableData: [],
            role:'',
        };
    },

    created() {
        this.init();
        this.initProjId();
    },
    methods: {
        initProjId() {
            let currentUser =this.global.currentUser;
            if(currentUser.currentRole == 1) {
                this.queryForm.projId = currentUser.currentManageDptId;
                this.initTrainingLevelOptions()
                this.handleSearch()
            } else {
                this.initProjs();
            }
            this.currentRole = currentUser.currentRole;
        },
        initTrainingLevelOptions() {
            findTrainingLevelByProjId(this.queryForm.projId).then(res => {
                if (res.code === 200) {
                    this.options.trainingLevel = res.data;
                    this.loadTrainingLevelOptions("trainingLevel", res.data);
                }
            });
        },
        loadTrainingLevelOptions(optionKey, dataObj) {
            this.options[optionKey] = [];
            this.options[optionKey] = dataObj.map(item => ({
                label:
                    "en" === this.$store.getters.language
                        ? item.nameEN
                        : item.nameCN,
                value: item.code
            }));
        },
        init() {
            this.queryForm["x-token"] =
                this.$store.state.session.sessionid ||
                localStorage.getItem("sessionid") ||
                "";
            this.initOptions();
        },
        async initProjs(){
            let params = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["X_GLBM"]
            };
            let res = await queryDic(params);
            let user = this.$store.state.session.user || JSON.parse(localStorage.getItem('user'));
            let {manageDptIds} = user;
            let {code, data: {X_GLBM}} = res;
            if (code === 200) {
                let dpts = Object.keys(X_GLBM).map(item => ({
                    label: X_GLBM[item],
                    value: item + ""
                }))
                this.options.project = (manageDptIds && manageDptIds instanceof Array && manageDptIds.length >0) ? dpts.filter(item => {
                    return manageDptIds.indexOf(item.value) > -1;
                }) : [];
            }
            this.queryForm.projId = this.options.project[0].value;
            this.initTrainingLevelOptions()
            this.handleSearch()
        },
        initOptions() {
            findFaculty().then(res => { 
                let data = {"X_YX": res.data};
                UTILS.fillSelect({ faculty: "X_YX" }, data, this.options);
            });
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["X_PYCC", "X_PYLB", "X_XXXS", "X_XWLX"]
            };
            queryDic(data).then(res => {
                if (res.code == 200) {
                    UTILS.fillSelect(
                        {
                            trainingLevel: "X_PYCC",
                            formLearning: "X_XXXS",
                            trainingCategory: "X_PYLB",
                            degreeType: "X_XWLX"
                        },
                        res.data,
                        this.options
                    );
                }
            });
        },
        handleSearch() {
            this.getCultureSchemes();
        },
        async getCultureSchemes() {
            await this.initTrainingLevelOptions();
            queryMinorCultureSchemeList(this.queryForm).then(res => {
                if (res.code == 200) {
                    this.tableData = res.data.list;
                    this.queryForm.pageNum_ = res.data.pageNum_;
                    this.queryForm.pageSize_ = res.data.pageSize_;
                    this.queryForm.total = res.data.total_;
                }
            });
        },
        pageChange(page) {
            this.queryForm.pageSize_ = page.pageSize;
            this.queryForm.pageNum_ = page.pageNum;
            this.getCultureSchemes();
        },
        selectionChange(selection) {
            this.multipleSelection = selection;
        },
        onSubmit() {
            this.getCultureSchemes();
        },
        reset(ref) {
            /* todo */
            this.queryForm.name = "";
            this.$refs[ref].resetFields();
            this.getCultureSchemes();
        },
        exportFile() {
            const ids = _.map(this.multipleSelection, "id");
            if(ids.length==0){
                this.$message({
                    type: "warning",
                    message: "请勾选培养方案再导出数据"
                });
                return; 
            }
            const str = ids.join(",");
            let data={
                ids:str,
                type :type,
                projId:this.queryForm.projId,
                status:this.queryForm.status
            };
            data['x-token']=this.queryForm['x-token'];
            exportCultureSchemePdfOrWordZip(data);
        },
    }
};
</script>
<style lang="scss" scoped>
.div-main {
    margin-bottom: 16px;
  }
</style>

